<%--                                                                       --%>
<%-- Copyright (c) 2004 BroadVision, Inc.  All rights reserved.            --%>
<%--                                                                       --%>
<%-- This software is copyrighted. Under the copyright laws, this software --%>
<%-- may not be copied, in whole or in part, without prior written consent --%>
<%-- of BroadVision, Inc. or its assignees. This software is provided      --%>
<%-- under the terms of a license between BroadVision and the recipient,   --%>
<%-- and its use is subject to the terms of that license.                  --%>
<%--                                                                       --%>
<%-- This software may be protected by one or more U.S. and International  --%>
<%-- patents.  Certain applications of BroadVision One-To-One software are --%>
<%-- covered by U.S. patent 5,710,887.                                     --%>
<%--                                                                       --%>
<%-- TRADEMARKS: BroadVision and BroadVision One-To-One are registered     --%>
<%-- trademarks of BroadVision, Inc., in the United States and the         --%>
<%-- European Community, and are trademarks of BroadVision, Inc., in other --%>
<%-- countries.  The BroadVision logo, is a trademark of BroadVision,      --%>
<%-- Inc., in the United States and other countries. Additionally, IONA    --%>
<%-- and Orbix are trademarks of IONA Technologies, Ltd.  RSA, MD5, and    --%>
<%-- RC2 are trademarks of RSA Data Security, Inc.                         --%>
<%--                                                                       --%>

<%@ taglib uri="/WEB-INF/struts-html-el.tld" prefix="html-el" %>
<%@ taglib uri="/WEB-INF/struts-bean-el.tld" prefix="bean-el" %>
<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>

<%@ include file="/ep/file/jspScriptPickerHelper.jsp" %>

<script language="JavaScript">
  
  // popup new window to select JSP
  function selectJspPopup() {
    jspScriptPickerPopup('setSelectedJsp');
  }
  
  // callback function
  function setSelectedJsp(jspPath) {
    document.epDisplayTemplateEditForm.primaryScriptPath.value = jspPath;
  }

  function doCancelAction(myform) {
    var ok = true;
    //if (checkAnyChange(myform) == true) {
    //  ok = confirm('<bean-el:message key="confirmCancel" bundle="ep.messages"/>');
    //}
    if (ok && myform != null) {
      myform.action = '<c:url value="/ep/channelDisplayTemplateList.do"/>';
      myform.submit();
    }
  }

  function doResetAction(myform) {
    if (checkAnyChange(myform) == true) {
      myform.reset();
    }
  }
  
  function checkAnyChange(myform) {
    trimTextFields(myform);
    if (myform.name.value != myform.name.defaultValue) {
      return true;
    }
    if (myform.description.value != myform.description.defaultValue) {
      return true;
    }
    if (myform.primaryScriptPath.value != myform.primaryScriptPath.defaultValue) {
      return true;
    }
    if (myform.primaryPageFlow.value != myform.primaryPageFlow.defaultValue) {
      return true;
    }
    return false;
  }

  function trimTextFields(myform) {
    var theName = myform.name.value;
    myform.name.value = theName.stringTrim();
    var theDescription = myform.description.value;
    myform.description.value = theDescription.stringTrim();
    var thePrimaryScriptPath = myform.primaryScriptPath.value;
    myform.primaryScriptPath.value = thePrimaryScriptPath.stringTrim();
    var thePrimaryPageFlow = myform.primaryPageFlow.value;
    myform.primaryPageFlow.value = thePrimaryPageFlow.stringTrim();
  }

  function doValidation(myform) {
    trimTextFields(myform);
    if (validateEpDisplayTemplateEditForm(myform) == false) {
      return false;
    }
    return true;
  }

</script>

<html-el:javascript formName="epDisplayTemplateEditForm"/>
<html-el:form action="/ep/channelDisplayTemplateSave.do" focus="name" onsubmit="return doValidation(epDisplayTemplateEditForm);">
<input type="hidden" name="displayTemplateId" value="<c:out value='${epDisplayTemplateEditForm.map.id}'/>"/>
<html-el:hidden property="id"/>
<table class="zoneFive" width="100%" border="0" cellspacing="0" cellpadding="0" summary="content area">
  <tr>
    <td valign="top" width="100%">
      <div class="pageTitle">
<c:choose>
  <c:when test="${epDisplayTemplateEditForm.map.id == 0}">
        <bean-el:message key="ep.channel.display.template.create.page.title" bundle="ep.messages"/>
  </c:when>
  <c:otherwise>
        <bean-el:message key="ep.channel.display.template.edit.page.title" arg0="${epDisplayTemplateEditForm.map.name}" bundle="ep.messages"/>
  </c:otherwise>
</c:choose> 
      </div>
      <div class="errorMessage"><html-el:errors bundle="ep.messages"/></div>
      <div class="pageSubtitle">
        <span class="left">
          <bean-el:message key="ep.display.template.information" bundle="ep.messages"/>
        </span>
        <span class="right">&nbsp;</span>
      </div> 
      <table class="labelForm" width="100%" border="0" cellspacing="0" cellpadding="0" summary="<bean-el:message key='ep.display.template' bundle="ep.messages"/>">
        <tr> 
          <td class="label" width="30%">
            <bean-el:message key="ep.display.template.name" bundle="ep.messages"/>:*
          </td>
          <td class="labelField" width="70%">
            <html-el:text name="epDisplayTemplateEditForm" property="name" size="30" maxlength="80"/> 
          </td>
        </tr>
        <tr> 
          <td class="label" width="30%">
            <bean-el:message key="ep.display.template.description" bundle="ep.messages"/>:
          </td>
          <td class="labelField" width="70%">
            <html-el:textarea name="epDisplayTemplateEditForm" property="description" rows="4" cols="50"/>
          </td>
        </tr>

<c:choose>
  <c:when test="${epDisplayTemplateEditForm.map.showJSP}">
        <tr> 
          <td class="label" width="30%">
  <c:choose>
     <c:when test="${epDisplayTemplateEditForm.map.showFlow}">
            <bean-el:message key="ep.display.template.script" bundle="ep.messages"/>:
     </c:when>
     <c:otherwise>
            <bean-el:message key="ep.display.template.script" bundle="ep.messages"/>:*
     </c:otherwise>
  </c:choose> 
          </td>
          <td class="labelField" width="70%">
            <html-el:text name="epDisplayTemplateEditForm" property="primaryScriptPath" size="50" maxlength="255" />
            <input type="button" name="selectJsp" class="pageButton" 
              onclick="JavaScript:selectJspPopup();" value='<bean-el:message key="button.browse" bundle="ep.messages"/>' align="top">
          </td>
        </tr>
  </c:when>
  <c:otherwise>	
  			<html-el:hidden name="epDisplayTemplateEditForm" property="primaryScriptPath" 
				value="${epDisplayTemplateEditForm.map.primaryScriptPath}"/>
  </c:otherwise>
</c:choose> 

<c:choose>
  <c:when test="${epDisplayTemplateEditForm.map.showFlow}">
        <tr> 
          <td class="label" width="30%">
            <bean-el:message key="ep.display.template.xflow" bundle="ep.messages"/>:
          </td>
          <td class="labelField" width="70%">
			<html-el:text name="epDisplayTemplateEditForm" property="primaryPageFlow" size="50" maxlength="255"/>
          </td>
        </tr>
  </c:when>
  <c:otherwise>
  			<html-el:hidden name="epDisplayTemplateEditForm" property="primaryPageFlow"
				value="${epDisplayTemplateEditForm.map.primaryPageFlow}"/>
  </c:otherwise>
</c:choose> 
      </table>

      <div class="pageButtonWrap" align="right">
        <input type="button" name="actionReset" class="pageButton" 
          onclick="doResetAction(this.form);"
          value='<bean-el:message key="button.reset" bundle="ep.messages"/>'>
        &nbsp;&nbsp;
        <input type="button" name="actionCancel" class="pageButton" 
          onclick="doCancelAction(this.form);"
          value='<bean-el:message key="button.cancel" bundle="ep.messages"/>'>
        <input type="submit" name="actionSaveContinue" class="pageButton"
          value='<bean-el:message key="button.save" bundle="ep.messages"/>'>
      </div>
    </td> 
  </tr>
</table>
</html-el:form> 
